<?php
$settings                = array(
	'enabled'           => Service_Kint_Main::$enabled,
	'displayCalledFrom' => Service_Kint_Main::$displayCalledFrom,
);
Service_Kint_Main::$enabled           = true;
Service_Kint_Main::$displayCalledFrom = false;

echo '<div class="kint kint-trace"><dl>';

foreach ( $output as $i => $step ) {
	echo '<dt class="kint-parent">'
		. '<b>' . ( $i + 1 ) . '</b> '
		. '<nav></nav>'
		. '<var>';

	if ( isset( $step['file'] ) ) {
		echo Service_Kint_Main::shortenPath( $step['file'], $step['line'] );
	} else {
		echo 'PHP internal call';
	}

	echo '</var>';

	echo $step['function'];

	if ( isset( $step['args'] ) ) {
		echo '(' . implode( ', ', array_keys( $step['args'] ) ) . ')';
	}
	echo '</dt><dd>';
	$firstTab = ' class="kint-active-tab"';
	echo '<ul class="kint-tabs">';

	if ( !empty( $step['source'] ) ) {
		echo "<li{$firstTab}>Source</li>";
		$firstTab = '';
	}

	if ( !empty( $step['args'] ) ) {
		echo "<li{$firstTab}>Arguments</li>";
		$firstTab = '';
	}

	if ( !empty( $step['object'] ) ) {
		kintParser::reset();
		$calleDump = kintParser::factory( $step['object'] );

		echo "<li{$firstTab}>Callee object [{$calleDump->subtype}]</li>";
		$firstTab = '';
	}


	echo '</ul><ul>';


	if ( !empty( $step['source'] ) ) {
		echo "<li><pre class=\"kint-source\">{$step['source']}</pre></li>";
	}

	if ( !empty( $step['args'] ) ) {
		echo "<li>";
		foreach ( $step['args'] as $k => $arg ) {
			kintParser::reset();
			echo Kint_Decorators_Rich::decorate( kintParser::factory( $arg, $k ) );
		}
		echo "</li>";
	}
	if ( !empty( $step['object'] ) ) {
		echo "<li>" . Kint_Decorators_Rich::decorate( $calleDump ) . "</li>";
	}

	echo '</ul></dd>';
}
echo '</dl></div>';
Service_Kint_Main::$enabled           = $settings['enabled'];
Service_Kint_Main::$displayCalledFrom = $settings['displayCalledFrom'];
unset( $settings );
